﻿using System;
using System.Web.Mvc;
using EasySite.Models;

namespace EasySite.Services
{
    public abstract class ServiceBase
    {
        private readonly EasySiteEntities _entities = new EasySiteEntities();
        protected EasySiteEntities DataContext
        {
            get { return _entities; }
        }

        protected bool TrySaveChanges()
        {
            try
            {
                DataContext.SaveChanges();
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        protected T GetService<T>()
        {
            return DependencyResolver.Current.GetService<T>();
        }
    }
}
